package com.doyoulearn.websocket.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebAlarmSocketConfig implements WebSocketMessageBrokerConfigurer {

    /**
     * 配置MessageBroker
     * setApplicationDestinationPrefixes：客户端发给服务器的路径前缀
     * enableSimpleBroker：服务端发送给客户端的前缀
     * @param config config
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/web/alarm");
        config.setApplicationDestinationPrefixes("/wink/video/v1.0.0");
    }

    /**
     * 注册端点 发布或者订阅消息的时候需要连接此端点
     * @param registry registry
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/web-alarm-websocket")
                .setAllowedOrigins("*")
                .withSockJS();
    }
}
